<?php

class VigilanteDB extends CI_Model {

    var $title = '';
    var $content = '';
    var $date = '';

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function get_last_ten_entries() {
        $query = $this->db->get('entries', 10);
        return $query->result();
    }

    function Insert_Tabl($arrData) {
        //$this->db->insert('vigilantes', $arrData);
        
        if(!empty($arrData["f_nac"]))
            $this->db->insert('vigilantes', $arrData);
        else{
            $arrData["f_nac"] = NULL;
            $this->db->insert('vigilantes', $arrData);
        }
    }

    function Insert_Table_vig_ctt($arrData) {
        
        if(!empty($arrData["f_fin"]))
            $this->db->insert('vigxctt', $arrData);
        else{
            $arrData["f_fin"] = NULL;
            $this->db->insert('vigxctt', $arrData);
        }
       
    }
    
    function Insert_Table_v_tel($arrData) {
        
        $this->db->insert('vxnt', $arrData);
        
    }
    
    function borrar_tablavigilante($item) {
        /*$this->db->where('ficha', $item['eliminar']);
        $this->db->delete('empleado');      */ 
        
        $q = $this->db->get_where('vigilantes', array('ci' => $item['eliminar']));
            if ($q->result()) {
            $this->db->where('ci',$item['eliminar']);
            $this->db->delete('vigilantes');
            return TRUE;
            } else { 
            return FALSE;
            }
    } 
    
    
    
    function update_entryvig($arrData,$arrData2,$arrData3) {
        
        $this->db->where('ci', $arrData['ci']);
        $q1 = $this->db->get('vigilantes'); 
        /*$this->db->where('ci_vig', $arrData2['ci_vig']);
        $this->db->where('cod_b', $arrData2['cod_b']);
        $this->db->where('cod_s', $arrData2['cod_s']);
        $this->db->where('f_ini', $arrData2['f_ini']);
        $q2 = $this->db->get('vigxctt');
        $this->db->where('ci', $arrData3['ci']);
        //$this->db->where('num_telf', $arrData3['num_telf']);
        $q3 = $this->db->get('vxnt');*/
        
        if ($q1->num_rows() > 0) {
               $this->db->where('ci', $arrData['ci']);
               $this->db->update('vigilantes', $arrData);
               
              return TRUE;
             }else FALSE;
        
        /* if(!empty($arrData["f_nac"]) && !empty($arrData2["f_fin"])){           
                        if ($q1->num_rows() > 0) {
                            $this->db->where('ci', $arrData['ci']);
                            $this->db->update('vigilantes', $arrData);
                            $this->db->where('ci_vig', $arrData2['ci_vig']);
                            $this->db->where('cod_b', $arrData2['cod_b']);
                            $this->db->where('cod_s', $arrData2['cod_s']);
                            $this->db->where('f_ini', $arrData2['f_ini']);
                            $this->db->update('vigxctt', $arrData2);
                            $this->db->where('ci', $arrData3['ci']);
                            $this->db->where('num_telf', $arrData3['num_telf']);
                            $this->db->update('vxnt', $arrData3);
                            return TRUE;
                        }else FALSE;
        }else{
            
            if (empty($arrData["f_nac"]) && !empty($arrData2["f_fin"])){
            $arrData["f_nac"] = NULL;   
                        if ($q1->num_rows() > 0) {
                            $this->db->where('ci', $arrData['ci']);
                            $this->db->update('vigilantes', $arrData);
                            $this->db->where('ci_vig', $arrData2['ci_vig']);
                            $this->db->where('cod_b', $arrData2['cod_b']);
                            $this->db->where('cod_s', $arrData2['cod_s']);
                            $this->db->where('f_ini', $arrData2['f_ini']);
                            $this->db->update('vigxctt', $arrData2);
                            $this->db->where('ci', $arrData3['ci']);
                            $this->db->where('num_telf', $arrData3['num_telf']);
                            $this->db->update('vxnt', $arrData3);
                            return TRUE;
                        }else FALSE;
                        
            }
            
            if (!empty($arrData["f_nac"]) && empty($arrData2["f_fin"])){
            $arrData["f_fin"] = NULL;   
                        if ($q1->num_rows() > 0) {
                            $this->db->where('ci', $arrData['ci']);
                            $this->db->update('vigilantes', $arrData);
                            $this->db->where('ci_vig', $arrData2['ci_vig']);
                            $this->db->where('cod_b', $arrData2['cod_b']);
                            $this->db->where('cod_s', $arrData2['cod_s']);
                            $this->db->where('f_ini', $arrData2['f_ini']);
                            $this->db->update('vigxctt', $arrData2);
                            $this->db->where('ci', $arrData3['ci']);
                            $this->db->where('num_telf', $arrData3['num_telf']);
                            $this->db->update('vxnt', $arrData3);
                            return TRUE;
                        }else FALSE;
                        
            }*/
            
            
        
        
  
                        
    }
}
